package com.workstudy.web.controller.workstudy;

import com.workstudy.system.service.ISysUserService;
import com.workstudy.workstudy.domain.StatisticsDept;
import com.workstudy.workstudy.domain.StatisticsRole;
import com.workstudy.workstudy.domain.StatisticsSex;
import com.workstudy.workstudy.domain.WorkstudyPostUser;
import com.workstudy.workstudy.service.IWorkstudyAttendanceService;
import com.workstudy.workstudy.service.IWorkstudyPostUserService;
import com.workstudy.workstudy.service.IWorkstudyWageService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

@Controller
@RequestMapping("/workstudy/statistics")
public class StatisticsController {

    private String prefix = "workstudy/statistics";

    @Autowired
    private ISysUserService userService;

    @Autowired
    private IWorkstudyWageService workstudyWageService;

    @Autowired
    private IWorkstudyAttendanceService workstudyAttendanceService;

    @RequiresPermissions("workstudy:statistics:view")
    @GetMapping()
    public String attendance()
    {
        return prefix + "/list";
    }

    //统计性别
    @GetMapping("/selectUserBySumSex")
    @ResponseBody
    public StatisticsSex  selectUserBySumSex(){
        StatisticsSex sex = userService.selectUserBySumSex();
        return sex;
    }


    //统计每个学院的人数
    @GetMapping("/selectUserByDeptCount")
    @ResponseBody
    public List<StatisticsDept>  selectUserByDeptCount(){
        List<StatisticsDept> statisticsDepts = userService.selectUserByDeptCount();
        return statisticsDepts;
    }

    //用人单位发布岗位的数量
    @GetMapping("/selectWorkstudyAttendanceByCountRoleId")
    @ResponseBody
    public List<StatisticsRole> selectWorkstudyAttendanceByCountRoleId(){
        return workstudyAttendanceService.selectWorkstudyAttendanceByCountRoleId();
    }

    //统计出每个用户的总工资
    @GetMapping("/selectBySumSumprice")
    @ResponseBody
    public HashMap<String,Object>  selectBySumSumprice(){
        HashMap<String,Object> map=new HashMap<>();
        List<String> strings = workstudyWageService.selectBySumSumprice();
        long count1 = strings.stream().filter(u -> Integer.parseInt(u.substring(0,u.length()-3))>0 && Integer.parseInt(u.substring(0,u.length()-3))<300).count();
        long count2 = strings.stream().filter(u -> Integer.parseInt(u.substring(0,u.length()-3))>301 && Integer.parseInt(u.substring(0,u.length()-3))<600).count();
        long count3 = strings.stream().filter(u -> Integer.parseInt(u.substring(0,u.length()-3))>601 && Integer.parseInt(u.substring(0,u.length()-3))<800).count();
        long count4 = strings.stream().filter(u -> Integer.parseInt(u.substring(0,u.length()-3))>801).count();
        map.put("count1",count1);
        map.put("count2",count2);
        map.put("count3",count3);
        map.put("count4",count4);
        return map;
    }
}
